import axios from 'axios'
import { baseURL } from '../configFile'
import ArticleType from "../types/ArticleType";
import ArticleInfo from "../types/ArticleInfo";



const axiosReq = axios.create({
    baseURL
})
//列出文章列表
export const listArticleInfoReq = (articleType: string, offset: number, limit: number) => {
    return axiosReq.get('/listArticleInfo', { params: { articleType, offset, limit } })
}

//根据用户ID请求所属文章列表
export const listArticleOnID = (articleType: string, offset: number, limit: number, userID: number) => {
    return axiosReq.get('/listArticleOnID', { params: { articleType, offset, limit, userID } })
}

//查询文章数量
export const queryArticleAmount = (articleType: string) => {
    return axiosReq.get('/queryArticleAmount', { params: { articleType } })
}

//根据用户ID请求所属文章数量
export const queryArticleAmountOnID = (articleType: string, userID: number) => {
    return axiosReq.get('/queryArticleAmountOnID', { params: { articleType, userID } })
}

//查询文章信息
export const queryArticleInfo = (articleID: number) => {
    return axiosReq.get('/queryArticleInfo', { params: { articleID } })
}

//添加文章
export const addArticle = (articleType: ArticleType, title: String, content: String) => {
    return axiosReq.post('/addArticle', { articleType, title, content })
}

//删除文章
export const deleteArticle = (articleID: number) => {
    return axiosReq.post('/deleteArticle', { 'articleID': articleID })
}

//修改文章信息
export const modifyArticle = (articleInfo: Pick<ArticleInfo, 'articleID'> & Partial<Pick<ArticleInfo, 'title' | 'content'>>) => {
    return axiosReq.post('/modifyArticleInfo', { articleInfo })
}

//根据keyword搜索
export const searchArticleInfo = (keyword: string, articleType: ArticleType) => {
    return axiosReq.get('/searchArticleInfo', { params: { keyword, articleType } })
}

//恢复已删除文章
export const deletedArticleRecover = (articleID: number) => {
    return axiosReq.post('/deletedArticleRecover', { articleID })
}

//列出已删除文章
export const listDeletedArticleInfo = (articleType: ArticleType, offset: number, limit: number) => {
    return axiosReq.get('/listDeletedArticleInfo', { params: { articleType, offset, limit } })
}

//已删除文章数量
export const queryDeletedArticleAmount = (articleType: ArticleType) => {
    return axiosReq.get('/queryDeletedArticleAmount', { params: { articleType } })
}

//根据用户id搜索文章
export const searchArticleInfoOnID = (articleType: ArticleType, keyword: string) => {
    return axiosReq.get('/searchArticleInfoOnID', { params: { articleType, keyword } })
}

//获取文章封面
export const queryArticlePicturePath = (articleID: number) => {
    return axiosReq.get('/queryArticlePicturePath', { params: { articleID } })
}


